package aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class LogAspect {
	private final String pointcut = "execution(* AOPService.WorkService.work(String))";
//	@Before(value="execution(* AOPService.WorkService.work(String))")
	@Before(value=pointcut)
	public void logBefore() {
		System.out.println("log before...");
	}
	@After(value="execution(* AOPService.WorkService.work(String))")
	public void logAfter() {
		System.out.println("log after...");
	}
	
	@Around(value=pointcut)
	public Object logAround(ProceedingJoinPoint pjp) {
		String string = "";
//		String string = (String) pjp.getArgs()[0];
		string = "angers";
		Object object = null;
		System.out.println("log arount brfore...");
		try {
			//call target  当不执行该操作，返回空值，target不执行
//			object = pjp.proceed();//call target 过程
//			object = pjp.proceed(new Object[] {"angers"});
			object = pjp.proceed(new Object[] {string.toUpperCase()});
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("log arount brfore...");
		return object;
	}
}
